package cn.anc.aonicardv.util;

import android.content.Context;
import android.os.Build;
import android.util.DisplayMetrics;

import java.util.Locale;


/**
 * 本地设备信息配置.
 * <p/>
 * 包含设备屏幕信息、系统语言、设备唯一ID.
 * <p/>
 * Created by loh@weipaidang.net on 2016/11/17 0017.
 */
@SuppressWarnings("unused")
public final class DeviceInfo {
    private static final String TAG = "llcTest_DeviceInfo";
    /** 设备类型 */
    public static final String DEVICE_TYPE = "android";
    /** 设备类型 */
    public static final int DEVICE_TYPE_android = 2;
    /** 屏幕高度 */
    public static int ScreenHeightPixels = -1;
    /** 屏幕宽度 */
    public static int ScreenWidthPixels = -1;
    /** 屏幕密度 */
    public static float ScreenDensity = -1;
    /** 屏幕密度 */
    public static int ScreenDensityDpi = -1;
    /** 屏幕字体密度 */
    public static float ScreenScaledDensity = -1;
    /** 初次运行时系统语言环境 */
    public static String systemLastLocale = null;
    /** 设备品牌厂商信息 */
    public static String DEVICES_INFO = "(android; BRAND=" + Build.BRAND + "; MODEL=" + Build.MODEL + "; OS=" + Build.VERSION.RELEASE + " )";

    /** 初始化本地配置 */
    public static void init(Context context) {
        initDisplayMetrics(context);
        systemLastLocale = Locale.getDefault().toString();
        printfDeviceInfo();
    }

    /**
     * 屏幕信息获取<br/>
     * 使用Resources获取
     */
    private static void initDisplayMetrics(Context context) {
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        ScreenHeightPixels = dm.heightPixels;// 高
        ScreenWidthPixels = dm.widthPixels;// 宽
        ScreenDensity = dm.density;// 密度
        ScreenDensityDpi = dm.densityDpi;//
        ScreenScaledDensity = dm.scaledDensity;
    }

    public static String getDisplay() {
        return "Width:" + ScreenWidthPixels + "height:" + ScreenHeightPixels + "density:" + ScreenDensity + "Dpi:" + ScreenDensityDpi + "textdensity:" + ScreenScaledDensity+"deviceInfo:"+DEVICES_INFO;
    }


    private static void printfDeviceInfo() {
        LogUtil.i(TAG, "----------DeviceInfo start----------");
        LogUtil.i(TAG, "ScreenHeightPixels:", ScreenHeightPixels, ", ScreenWidthPixels:", ScreenWidthPixels);
        LogUtil.i(TAG, "ScreenDensity:", ScreenDensity, ", ScreenDensityDpi:", ScreenDensityDpi, ", ScreenScaledDensity:", ScreenScaledDensity);
        LogUtil.i(TAG, "DEVICES_INFO:" + DEVICES_INFO);
        LogUtil.i(TAG, "AndroidSDK:" + getAndroidSDKVersion());
        LogUtil.i(TAG, "----------DeviceInfo end----------");
    }
    public static String getDeviceInfo() {
        final StringBuffer logInfo = new StringBuffer();
        logInfo.append("-BRAND : " + Build.BRAND);
        logInfo.append("\n-MODEL : " +  Build.MODEL);
        logInfo.append("\n-OS : " + Build.VERSION.RELEASE);
        logInfo.append("\n-ScreenHeightPixels : " + ScreenHeightPixels);
        logInfo.append("\n-ScreenWidthPixels : " + ScreenWidthPixels);
        logInfo.append("\n-ScreenDensity : " + ScreenDensity);
        logInfo.append("\n-ScreenDensityDpi : " + ScreenDensityDpi);
        logInfo.append("\n-ScreenScaledDensity : " + ScreenScaledDensity);
        return logInfo.toString();
    }

    public static String getDeviceModel() {
        return Build.MODEL;
    }

    public static int getAndroidSDKVersion() {
        int version = 0;

        try {
            version = Integer.valueOf(android.os.Build.VERSION.SDK);

        } catch (NumberFormatException e) {
        }
        return version;

    }
}
